package com.easyaop.core.matcher;

import com.easyaop.api.pointcut.AnnotationPointcut;
import com.easyaop.api.pointcut.MethodObjectForBuddy;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

public class CustomAnnotationMatcher implements ElementMatcher<MethodDescription> {
    private final AnnotationPointcut pointcut;

    public CustomAnnotationMatcher(AnnotationPointcut pointcut) {
        this.pointcut = pointcut;
    }

    @Override
    public boolean matches(MethodDescription methodDescription) {
        return pointcut.isMethod(new MethodObjectForBuddy(methodDescription));

//        AnnotationList annotations = methodDescription.getDeclaredAnnotations();
//        if (annotations.isEmpty()) {
//            return false;
//        }
//        for (AnnotationDescription annotation : annotations) {
//            if (annotation.getAnnotationType().getName().equals(pointcut.getAnnotation())) {
//                return true;
//            }
//        }
//        return false;
    }
}